Diamond image from Unsplash (Dan 2022)
Diamond gif from Tenor (AnitaCruz2324 2025)
Size matters!
A histogram of diamond weight (carat), using 10 bins.
A histogram of diamond weight (carat), using 100 bins.
The regression equation:
\(Y_{\text{price}} = \beta_0 + \beta_1 X_{\text{carat}} + \beta_2 X_{\text{cut}} + \\ \beta_3 X_{\text{depth}} + \beta_4 X_{\text{x}} + \beta_5 X_{\text{y}} + \beta_6 X_{\text{z}}\)
# load diamonds dataset
library(ggplot2)
data(diamonds)
# randomly sample 5000 diamonds
set.seed(42)
diamonds_sample <- diamonds[sample(nrow(diamonds), 5000),
c("carat", "cut", "depth", "x",
"y", "z", "price")]
# fit a linear regression model
model <- lm(price ~ carat + cut + depth + x + y + z,
data = diamonds_sample)
summary(model)The dataset used in this analysis is included in the ggplot2 package (Wickham 2016).